package com.itheima.job3;

import java.util.ArrayList;

public class Test {
    public static void main(String[] args) {
        ArrayList<Student> students = new ArrayList<>();
        students.add(new Student("张三",23,"男"));
        students.add(new Student("李四",52,"男"));
        students.add(new Student("王五",43,"男"));
        int max = students.get(0).getAge();
          int max = students.get(0).getAge();
        for (int i = 1; i < students.size(); i++) {
            if (students.get(i).getAge() > max) {
                max = students.get(i).getAge();
            }
        }
        for (int i = 0; i < students.size(); i++){
            if (students.get(i).getAge() == max){
                students.get(i).setName("小猪佩奇");
                students.set(i,students.get(i));
            }
        }
            students.forEach(student -> System.out.println(student));

    }
}
